﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web;
using System.IO;
using Newtonsoft.Json;
using iver.Entity;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using DBEntity;
namespace iver.Controllers
{


    public class CommonController : ApiController
    {
        #region 上传文件
        /// <summary>
        /// 上传的文件对象模型
        /// </summary>
        public class uploadFile
        {
            /// <summary>
            /// 生成的文件名不带后缀，GUID生成
            /// </summary>
            public string id { set; get; }
            /// <summary>
            /// 原文件名
            /// </summary>
            public string oldname { set; get; }
            /// <summary>
            /// 保存的文件名，文件地址
            /// </summary>
            public string filepath { set; get; }
            /// <summary>
            /// 网络地址
            /// </summary>
            public string webpath { set; get; }
            ///// <summary>
            ///// 文件标签
            ///// </summary>
            //public string tag { set; get; }
            ///// <summary>
            ///// 备注
            ///// </summary>
            //public string remark { set; get; }
        }
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResResult uploadfile()
        {
            Entity.AuthInfo authInfo;
            if (!ReqBase.isAuth(out authInfo))
            {
                return new ResResult
                {
                    success = false,
                    rescode = ResCode.FailAuth,
                };
            }
            return Help.uploadfile("video", 3);
        }
        #endregion

        #region 图片验证码

        /// <summary>
        /// 生成图片验证码
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResResult imgcode([FromBody] ReqImgCode req)
        {
            return Help.imgcode(req);
        }

        #endregion

        #region 读写文件数据库

        [HttpPost]
        public ResResult writetable([FromBody] ReqKeyValuePair req)
        {
            AuthInfo authInfo;
            if (!ReqBase.isAuth(out authInfo))
            {
                return new ResResult
                {
                    success = false,
                    rescode = ResCode.FailAuth,
                };
            }
            return Help.writetable(req);
        }
        public ResResult readtable([FromBody] ReqKeyValuePair req)
        {
            AuthInfo authInfo;
            if (!ReqBase.isAuth(out authInfo))
            {
                return new ResResult
                {
                    success = false,
                    rescode = ResCode.FailAuth,
                };
            }
            return Help.readtable(req);
        }
        #endregion
        
    }
}